<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function deepCopy(target) {
        if (typeof target !== 'object') {
          return target;
        }
        var result = Array.isArray(target) ? [] : {};
        if (Array.isArray(target)) {
          for (var i = 0; i < target.length; i++) {
            //多层拷贝用递归函数
            result.push=deepCopy(target[i]);
          }
        } else {
          for (var k in target) {
            result[k] =deepCopy(target[k]) ;
          }
        }
        return result;
      }
      var hobby = ['aihao'];
      var hobby2 = deepCopy(hobby);
      console.log(hobby2);
      var obj1 = {name :'lisi'}
      var obj2 = deepCopy(obj1)
      console.log(obj2)
    </script>
  </body>
</html>
